extends CardState

var origin_possition
var can_use


func on_card_release() -> void:
	if card_view.card.card_type != Card.CARD_TYPE.COM:
		if can_use:
			transition_requested.emit(self, State.STATE_RELEASE)
			return
		else:
			transition_requested.emit(self, State.STATE_IN_HAND)
	if Globals.current_monster == null:
		transition_requested.emit(self, State.STATE_IN_HAND)
	else:
		transition_requested.emit(self, State.STATE_RELEASE)


func enter() -> void:
	card_view.card_container.organize_cards.emit(false, true, false, card_view)
	origin_possition = card_view.global_position
	card_view.border_panel.set("theme_override_styles/panel", card_view.PICKUP_STYLEBOX)


func update_transform(_in_hand_rotation, _in_hand_position, _in_hand_hover_position):
	card_view.z_index = 100


func _process(_delta):
	if get_parent().current_state == self:
		if card_view.card.card_type != Card.CARD_TYPE.COM:
			card_view.global_position = card_view.get_global_mouse_position()
			if abs(origin_possition.y - card_view.global_position.y) > 200:
				can_use = true
				card_view.border_panel.set("theme_override_styles/panel", card_view.USE_STYLEBOX)
			else:
				can_use = false
				card_view.border_panel.set("theme_override_styles/panel", card_view.PICKUP_STYLEBOX)
		else:
			if Globals.current_monster != null:
				can_use = true
				card_view.update_label_on_pickup(true, Globals.current_monster)
				card_view.border_panel.set("theme_override_styles/panel", card_view.USE_STYLEBOX)
			else:
				can_use = false
				card_view.update_label_on_pickup(false, Globals.current_monster)
				card_view.border_panel.set("theme_override_styles/panel", card_view.PICKUP_STYLEBOX)
